﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;
using DevExpress.XtraEditors;
using Ebada.Platform.Model;
using Ebada.UI.Base;
using Ebada.Client;
using Ebada.Core;
using Ebada.Client.Platform;
namespace Ebada.Modules.Document
{
    /// <summary>
    /// 单证类型编辑
    /// </summary>
    public partial class frmDocumentTypeEdit : FormBase, IPopupFormEdit {
        SortableSearchableBindingList<Activities> m_Act = new SortableSearchableBindingList<Activities>();

        public frmDocumentTypeEdit() {
            InitializeComponent();
        }
        void dataBind() {
            this.txtCnFullName.DataBindings.Add("EditValue", rowData, "DocTypeDes");
            this.txtCnName.DataBindings.Add("EditValue", rowData, "DocTypeName");
            this.txtEnFullName.DataBindings.Add("EditValue", rowData, "Act_Name");
            this.txtEnName.DataBindings.Add("EditValue", rowData, "Act_Code");
            this.dateEdit1.DataBindings.Add("EditValue", rowData, "SubmitDate");
            this.dateEdit2.DataBindings.Add("EditValue", rowData, "ValidityDate");
            this.dateEdit3.DataBindings.Add("EditValue", rowData, "RemindDate");
            this.dateEdit4.DataBindings.Add("EditValue", rowData, "ReturnDate");
        }
        #region IPopupFormEdit Members
        private DocumentType rowData = null;

        public object RowData {
            get {
                return rowData;
            }
            set {
                if (value == null) return;
                if (rowData == null) {
                    this.rowData = value as DocumentType;
                    dataBind();
                    InitComboBoxData();
                } else {
                    ConvertHelper.CopyTo<DocumentType>(value as DocumentType, rowData);
                }
            }
        }

        #endregion

        private void InitComboBoxData() {
            //this.m_Act.Clear();
            //this.m_Act.Add(MainHelper.GetSqlMap<Activities>().GetList<Activities>(null));
           // this.SetComboBoxData(this.txtEnName, "Act_Code", "Act_Code", "请选择", "", this.m_Act);
        }

        /// <summary>
        /// 
        /// </summary>
        /// <param name="comboBox"></param>
        /// <param name="displayMember"></param>
        /// <param name="valueMember"></param>
        /// <param name="nullTest"></param>
        /// <param name="cnStr"></param>
        /// <param name="post"></param>
        public void SetComboBoxData(DevExpress.XtraEditors.LookUpEdit comboBox, string displayMember, string valueMember, string nullTest, string cnStr, SortableSearchableBindingList<Activities> post)
        {
            comboBox.Properties.TextEditStyle = DevExpress.XtraEditors.Controls.TextEditStyles.DisableTextEditor;
            comboBox.Properties.DataSource = post;
            comboBox.Properties.DisplayMember = displayMember;
            comboBox.Properties.ValueMember = valueMember;
            comboBox.Properties.NullText = nullTest;
        }

        private void txtEnName_EditValueChanged(object sender, EventArgs e)
        {

        }

        private void buttonEdit1_Properties_Click(object sender, EventArgs e)
        {
            Ebada.Client.Platform.Selector.frmActivitiesSelector f = new Ebada.Client.Platform.Selector.frmActivitiesSelector();
            f.StartPosition = FormStartPosition.CenterScreen;
            f.ucActivities1.bar1.Visible = false;
            f.SetCoulos();
            if (f.ShowDialog() == DialogResult.OK)
            {
                txtEnFullName.Text = f.Activitie.Act_Name;
                txtEnName.Text = f.Activitie.Act_Code; ;
                rowData.Act_Name = txtEnFullName.Text;
            }
        }

        private void btnOK_Click(object sender, EventArgs e)
        {
            if (txtCnName.Text == "")
            {
                MessageBox.Show("种类名称不能为空。", "提示", MessageBoxButtons.OK, MessageBoxIcon.Information);
                txtCnName.Focus();
                return;
            }
            IList<DocumentType> objlist = MainHelper.GetSqlMap<DocumentType>().GetListByWhere<DocumentType>(" where DocumentTypeID='" + rowData.DocumentTypeID + "'");
            if (objlist.Count > 0)
            {
                if (rowData.DocumentTypeID == objlist[0].DocumentTypeID)
                {
                    rowData.LastEditUserID = MainHelper.UserBaseX.User_ID;
                    rowData.LastEditUserName = MainHelper.UserBaseX.Empolyee_Name;
                    rowData.LastEditTime = DateTime.Now;
                }
            }
            else
            {
                rowData.CreateUserID = MainHelper.UserBaseX.User_ID;
                rowData.CreateUserName = MainHelper.UserBaseX.Empolyee_Name;
                rowData.CreatedDate = DateTime.Now;
            }
            this.DialogResult = DialogResult.OK;
            this.Close();
        }
    }
}